<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div style="width: 100px;height: 5000px"></div>
</body>
<script>
    // var timeout = null;
    // // 防抖----------执行最后一次操作
    // function debounce(fn, wait) {
    //     return function() {
    //         if(timeout !== null)  clearTimeout(timeout);
    //         timeout = setTimeout(fn, wait);
    //     }
    // }
    // // 处理函数
    // function handle() {
    //     console.log(Math.random());
    // }
    // // 滚动事件
    // window.addEventListener('scroll', debounce(handle, 600));
    //
    //
    //
    var throttle = function(func, delay) {
        var prev = Date.now();
        return function() {
            var context = this;   //this指向window
            var args = arguments;
            var now = Date.now();
            if (now - prev >= delay) {
                func.apply(context, args);
                prev = Date.now();
            }
        }
    }
    function handle() {
        console.log(Math.random());
    }
    window.addEventListener('scroll', throttle(handle, 1000));

</script>
</html>